$('.h_logo').click(function(){
    location.href="./home.html"
})

if(!location.search){
    layer.msg('非法进入自动返回首页',function(){
        location.href="./home.html"
    })
}

// 商品请求
$.get("./data/list.json",function(data){
    var dataid=location.search
    dataid=dataid.split('=')
    var arr=["手机","电视","笔记本","家电","出行佩戴","智能","电源配件","健康儿童","耳机音箱","生活箱包"]
    data.forEach(item => {   
        if(item.id==dataid[1]){
            var str=''
            str+=`<div class="cell_left"><div class="figule"><a href="./Details.html?pid=${item.pid}"><img src=${item.imgsrc} </a></div><h3><a href="./Details.html?id=${item.pid}">${item.name}</a></h3><p class="desc">
            ${item.text}</p><p class="comprice"><strong>${item.price}</strong>元起</p></div>`
            var div=document.createElement('div')
            $(div).addClass('produt_cell clearfix')
            $(div).html(str)
        }
        $('.star').append(div) 
        if(dataid[1]==2){
            $('#listmain').css('backgroundColor',"#F6AB2E")
        }
    });
    var h2=$(`<h2 class="st-tit">${arr[dataid[1]-1]}</h2>`)
    $('.star').prepend(h2) 
})



// 请求banner.json广告图
$.get("./data/banner.json",function(data){
    var dataid=location.search
    dataid=dataid.split('=')
    for (const item in data) {
        // console.log(data[item].id);
        if(data[item].id==dataid[1]){
            $('.listbanner>a').css(
                {
                    "background":`url(${data[item].imgsrc})no-repeat center`,
                    "display": "block",
                    "width": "100%",
                    "backgroundSize": "auto 620px",
                    "height": "620px",
                    "margin": "0 auto"
                  }

                
            )
            $('.listbanner>a').attr("href",`./Details.html?pid=${data[item].pid}`)
            console.log($('.listbanner>a'));
            // console.log(data[item].imgsrc);
        }
    }
})